 import React, { Component } from 'react';
 import api from '../api/api'
 import { Route, Switch, Redirect, withRouter } from 'react-router-dom'
 class AuthRouter extends Component {
	checkLogin() {
    api.checkLogin().then(res => {
      debugger
      if(res.code === 20000) {
        return true
      }else {
        return false
      }
    })
	}
	componentWillMount(){
    let isAuthenticated =  this.checkLogin() ? true :false;
    debugger
		this.setState({isAuthenticated:isAuthenticated})
		if(!isAuthenticated){
			const {history} = this.props;
			setTimeout(() => {
				history.replace("/login");
			}, 1000)
		}
	}
	render() {
		return (
			<this.props.component>
			</this.props.component>
		)
	}
}

export default withRouter(AuthRouter)